package com.pxx.item.controller;

import com.pxx.common.utils.PageResult;
import com.pxx.item.pojo.SpuBo;
import com.pxx.item.pojo.TbBrand;
import com.pxx.item.pojo.TbSpu;
import com.pxx.item.pojo.TbSpuDetail;
import com.pxx.item.service.TbBrandService;
import com.pxx.item.service.TbSpuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.BitSet;
import java.util.List;

/**
 * @author : Yoo19
 * @description :
 * @createDate : 2025/6/27 8:11 11
 */

@RestController
@RequestMapping("/item/spu/")
public class SpuController {
    @Autowired
    private TbSpuService tbSpuService;
    @Autowired
    private TbBrandService tbBrandService;

    @GetMapping("/page")
    public ResponseEntity<PageResult<SpuBo>> querySpuBoByPage(
            @RequestParam(value = "page",defaultValue = "1")Integer page,
            @RequestParam(value = "rows",defaultValue = "5")Integer rows,
            @RequestParam(value = "key",required = false)String key,
            @RequestParam(value = "saleable",defaultValue = "false")Boolean saleable
    ){
        PageResult<SpuBo> result = tbSpuService.querySpuBoByPage(page,rows,key,saleable);
        if(CollectionUtils.isEmpty(result.getItems())){
            return ResponseEntity.notFound().build();
        }
        return ResponseEntity.ok(result);
    }

    /**
     * 根据spuId查询SpuDetail
     * @param spuId
     * @return
     */
    @GetMapping("/detail/{spuId}")
    public ResponseEntity<TbSpuDetail> querySpuDetailBySpuId(@PathVariable("spuId")Long spuId){
      TbSpuDetail tbSpuDetail = tbSpuService.querySpuDetailBySpuId(spuId);
        return ResponseEntity.ok(tbSpuDetail);
    }


}
